﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Globalization;

namespace YSCommander
{
	//// <summary>
	/// Interaction logic for AboutWindow.xaml
	/// </summary>
	public partial class AboutWindow : Window
	{

		#region Properties

		public static string AssemblyTitle
		{
			get
			{
				object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
				if (attributes.Length > 0)
				{
					AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes[0];
					if (0 != titleAttribute.Title.Length)
					{
						return titleAttribute.Title;
					}
				}
				return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);
			}
		}

		public static string AssemblyVersion
		{
			get
			{
				return Assembly.GetExecutingAssembly().GetName().Version.ToString();
			}
		}

		public static string AssemblyDescription
		{
			get
			{
				object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false);
				if (attributes.Length == 0)
				{
					return "";
				}
				return ((AssemblyDescriptionAttribute)attributes[0]).Description;
			}
		}

		public static string AssemblyProduct
		{
			get
			{
				object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), false);
				if (attributes.Length == 0)
				{
					return "";
				}
				return ((AssemblyProductAttribute)attributes[0]).Product;
			}
		}

		public static string AssemblyCopyright
		{
			get
			{
				object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
				if (attributes.Length == 0)
				{
					return "";
				}
				return ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
			}
		}

		public static string AssemblyCompany
		{
			get
			{
				object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false);
				if (attributes.Length == 0)
				{
					return "";
				}
				return ((AssemblyCompanyAttribute)attributes[0]).Company;
			}
		}
		#endregion Properties

		#region Methods

		public AboutWindow()
		{
			InitializeComponent();
		}

		private void Window_Loaded(object sender, RoutedEventArgs e)
		{
			Title = String.Format(CultureInfo.InvariantCulture, "About {0}", AssemblyTitle.ToString());
			textBlockProductName.Text = AssemblyProduct;
			textBlockVersion.Text = String.Format(CultureInfo.InvariantCulture, "Version {0}", AssemblyVersion.ToString());
			textBlockCopyright.Text = AssemblyCopyright;
			textBlockCompanyName.Text = AssemblyCompany;
			textBlockDescription.Text = AssemblyDescription;
		}

		#endregion Methods

		private void Button_Click(object sender, RoutedEventArgs e)
		{
			Close();
		}

		//private void textBlockLink_MouseDown(object sender, MouseButtonEventArgs e)
		//{

		//    System.Diagnostics.Process p = new System.Diagnostics.Process();
		//    p.StartInfo.FileName = textBlockLink.Text;
		//    p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
		//    p.Start();

		//}

		private void hyperlinkToSite_Click(object sender, RoutedEventArgs e)
		{
			System.Diagnostics.Process p = new System.Diagnostics.Process();
			p.StartInfo.FileName = hyperlinkToSite.NavigateUri.ToString();
			p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
			p.Start();

			e.Handled = true;
		}
	}
}

